home *** CD-ROM | disk | FTP | other *** search
/ The 640 MEG Shareware Studio 4 / The 640 Meg Shareware Studio CD-ROM Volume IV (Data Express)(1994).ISO / clang / xlib05.zip / XPOINT.ASM < prev    next >
Assembly Source File  |  1993-08-25  |  3KB  |  107 lines

  1. ;-----------------------------------------------------------------------
  2. ; MODULE XPOINT
  3. ;
  4. ; Point functions all MODE X 256 Color resolutions
  5. ;
  6. ; Compile with Tasm.
  7. ; C callable.
  8. ;
  9. ;
  10. ; ****** XLIB - Mode X graphics library                ****************
  11. ; ******                                               ****************
  12. ; ****** Written By Themie Gouthas                     ****************
  13. ;
  14. ; egg@dstos3.dsto.gov.au
  15. ; teg@bart.dsto.gov.au
  16. ;-----------------------------------------------------------------------
  17.  
  18.  
  19. include xlib.inc
  20. include xpoint.inc
  21.  
  22.     .code
  23.  
  24.  
  25. ;-----------------------------------------------------------------------
  26. ; Mode X (256 color mode) write pixel routine.
  27. ; No clipping is performed.
  28. ;
  29. ; Based on code originally published in DDJ Mag by M. Abrash
  30. ;
  31. ; C near-callable as:
  32. ;    void x_put_pix(int X, int Y, int PageOffset, int Color);
  33. ;
  34. ;
  35.  
  36. _x_put_pix  proc    
  37.     ARG X:word,Y:word,PgOfs:word,Color:word
  38.     push bp                   ;preserve caller's stack frame
  39.     mov  bp,sp                ;point to local stack frame
  40.  
  41.     mov  ax,[_ScrnLogicalByteWidth]
  42.     mul  [Y]                  ;offset of pixel's scan line in page
  43.     mov  bx,[X]
  44.     shr  bx,2                 ;X/4 = offset of pixel in scan line
  45.     add  bx,ax                ;offset of pixel in page
  46.     add  bx,[PgOfs]           ;offset of pixel in display memory
  47.     mov  ax,SCREEN_SEG
  48.     mov  es,ax                ;point ES:BX to the pixel's address
  49.  
  50.     mov  cl,byte ptr [X]
  51.     and  cl,011b              ;CL = pixel's plane
  52.     mov  ax,0100h + MAP_MASK  ;AL = index in SC of Map Mask reg
  53.     shl  ah,cl                ;set only the bit for the pixel's
  54.                   ; plane to 1
  55.     mov  dx,SC_INDEX          ;set the Map Mask to enable only the
  56.     out  dx,ax          ; pixel's plane
  57.  
  58.     mov  al,byte ptr [Color]
  59.     mov  es:[bx],al           ;draw the pixel in the desired color
  60.  
  61.     pop   bp                  ;restore caller's stack frame
  62.     ret
  63. _x_put_pix   endp
  64.  
  65. ;-------------------------------------------------------------------------
  66. ; Mode X (320x240, 256 colors) read pixel routine. Works on all VGAs.
  67. ; No clipping is performed.
  68. ;
  69. ; Based on code originally published in DDJ Mag by M. Abrash
  70. ;
  71. ; C near-callable as:
  72. ;    unsigned int x_get_pix(int X, int Y, unsigned int PageBase);
  73.  
  74.  
  75. _x_get_pix   proc
  76.     ARG x:word,y:word,PageBase:word
  77.     push bp                   ;preserve caller's stack frame
  78.     mov  bp,sp                ;point to local stack frame
  79.  
  80.     mov  ax,[_ScrnLogicalByteWidth]
  81.     mul  [Y]                  ;offset of pixel's scan line in page
  82.     mov  bx,[X]
  83.     shr  bx,1
  84.     shr  bx,1                 ;X/4 = offset of pixel in scan line
  85.     add  bx,ax                ;offset of pixel in page
  86.     add  bx,[PageBase]        ;offset of pixel in display memory
  87.     mov  ax,SCREEN_SEG
  88.     mov  es,ax                ;point ES:BX to the pixel's address
  89.  
  90.     mov  ah,byte ptr [X]
  91.     and  ah,011b              ;AH = pixel's plane
  92.     mov  al,READ_MAP          ;AL = index in GC of the Read Map reg
  93.     mov  dx,GC_INDEX          ;set the Read Map to read the pixel's
  94.     out  dx,ax              ; plane
  95.  
  96.     mov  al,es:[bx]           ;read the pixel's color
  97.     sub  ah,ah                ;convert it to an unsigned int
  98.  
  99.     pop  bp                   ;restore caller's stack frame
  100.         ret
  101. _x_get_pix   endp
  102.         end
  103.  
  104.  
  105.     end
  106.  
  107.